package com.chainyoung.component_tmperson.ui.activity.financing;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chainyoung.common.base.BaseActivity;
import com.chainyoung.common.di.AppComponent;
import com.chainyoung.common.view.NoScrollListView;
import com.chainyoung.component_tmperson.R;
import com.chainyoung.component_tmperson.R2;
import com.chainyoung.component_tmperson.entity.WalletFinancing;
import com.chainyoung.component_tmperson.ui.adapter.FinancingProAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SelectFinaningProTypeActivity extends BaseActivity {


    @BindView(R2.id.list_active)
    NoScrollListView listActive;
    @BindView(R2.id.list_fixed)
    NoScrollListView listFixed;
    @BindView(R2.id.ll_active)
    LinearLayout llActive;
    @BindView(R2.id.ll_fixed)
    LinearLayout llFixed;

    private WalletFinancing data;
    private List<WalletFinancing.ListBean> mActiveList = new ArrayList<>();
    private List<WalletFinancing.ListBean> mFixedList = new ArrayList<>();

    private FinancingProAdapter activeAdapter;
    private FinancingProAdapter fixedAdapter;


    @Override
    protected void setupActivityComponent(AppComponent appComponent) {

    }

    @Override
    protected void initUI() {
        setCurrentTitle("增益类型");
        data = (WalletFinancing) getIntent().getSerializableExtra("walletFinancing");
        activeAdapter = new FinancingProAdapter(mContext, mActiveList, data.getMin_in(), data.getName());
        fixedAdapter = new FinancingProAdapter(mContext, mFixedList, data.getMin_in(), data.getName());
        listActive.setAdapter(activeAdapter);
        listFixed.setAdapter(fixedAdapter);
        listActive.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent data = new Intent();
                data.putExtra("result", mActiveList.get(position));
                setResult(RESULT_OK, data);
                finish();
            }
        });

        listFixed.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent data = new Intent();
                data.putExtra("result", mFixedList.get(position));
                setResult(RESULT_OK, data);
                finish();
            }
        });
    }

    @Override
    protected void initData() {
        mActiveList.clear();
        mFixedList.clear();
        for (WalletFinancing.ListBean item : data.getList()) {
            if (item.getType().equals("current")) {
                mActiveList.add(item);
            } else if (item.getType().equals("fixed")) {
                mFixedList.add(item);
            }
        }
        llActive.setVisibility(mActiveList.isEmpty() ? View.GONE : View.VISIBLE);
        llFixed.setVisibility(mFixedList.isEmpty() ? View.GONE : View.VISIBLE);
        activeAdapter.notifyDataSetChanged();
        fixedAdapter.notifyDataSetChanged();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.tmperson_select_financing_pro_type;
    }


}
